<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>任务调度中心-登录</title>
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta http-equiv="Access-Control-Allow-Origin" content="*">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="icon" href="/images/favicon.ico">
    <link rel="stylesheet" href="/lib/layui/css/layui.css?v=2.8.11" media="all">
    <!--[if lt IE 9]>
    <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
    <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
    <style>
        html, body {
            height: 100%;
            margin: 0;
            padding: 0;
        }

        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
            outline: none !important;
        }

        .login-container {
            width: 100%;
            height: 100%;
            background: url(/images/login/login-bg.png) no-repeat center;
            background-size: cover;
            display: flex;
            align-items: center;
            justify-content: center;
        }

        .login-container .box-item {
            width: 440px;
            height: 400px;
        }

        .login-container .box-item.desc {
            background: #ffffff;
            border-radius: 12px 0px 0px 12px;
            box-shadow: 0px 16px 73px 8px rgba(203, 203, 203, 0.2);
            padding: 23px 25px;
        }

        .login-container .box-item.login {
            background: #ffffff;
            border-radius: 0px 12px 12px 0px;
            padding: 34px 42px;
            position: relative;
        }

        .login-container .box-item p {
            color: #333333;
            line-height: 25px;
            letter-spacing: 0.26px;
            text-align: center;
            font-weight: 700;
            font-size: 26px;
        }

        .login-container .box-item .sub-welcome {
            padding: 10px;
            font-size: 18px;
            font-weight: 700;
            text-align: center;
            color: #ffffff;
            line-height: 25px;
            letter-spacing: 0.26px;
            opacity: 0.96;
            background: #006ad4;
            border-radius: 22px 22px 2px 22px;
            margin-top: 20px;
        }

        .login-form {
            margin-top: 50px;
        }
    </style>
</head>
<body>
<div class="login-container">
    <div class="box-item login">
        <p>欢迎使用 TINY-JOB</p>
        <p class="sub-welcome">「简洁、好用、安全」的任务调度平台</p>

        <div class="login-form">
            <form class="layui-form" action="">
                <div class="layui-form-item">
                    <div class="layui-input-wrap">
                        <div class="layui-input-prefix">
                            <i class="layui-icon layui-icon-username"></i>
                        </div>
                        <input type="text" name="username" value="" lay-verify="required|username" lay-vertype="tips" placeholder="用户名" lay-reqtext="请填写用户名" autocomplete="off" class="layui-input" lay-affix="clear">
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-input-wrap">
                        <div class="layui-input-prefix">
                            <i class="layui-icon layui-icon-password"></i>
                        </div>
                        <input type="password" name="password" value="" lay-verify="required|password" lay-vertype="tips" placeholder="密  码" lay-reqtext="请填写密码" autocomplete="off" class="layui-input" lay-affix="eye">
                    </div>
                </div>
                <div class="layui-form-item">
                    <button class="layui-btn layui-btn-fluid" lay-submit lay-filter="login" id="login">登 录</button>
                </div>
            </form>
        </div>
    </div>
</div>


<script src="/lib/crypto/sha256.js?v=2.0.0" charset="utf-8"></script>
<script src="/lib/layui/layui.js?v=2.8.11" charset="utf-8"></script>
<script src="/js/lay-config.js?v=2.0.0" charset="utf-8"></script>
<script src="/js/common.js?v=2.0.0" charset="utf-8"></script>
<script>
    var salt = "W%o$gxG6Nbbg+S4@W5&9VQeud&2O1^V8&We^YwhX-1N+_m7&KQ#JJ@a+UX9Rr5Bk";

    layui.use(['form', 'miniAjax', 'layer'], function () {
        var $ = layui.jquery,
            form = layui.form,
            layer = layui.layer,
            miniAjax = layui.miniAjax;

        // 登录过期的时候，跳出iframe框架
        if (top.location != self.location) {
            top.location = self.location;
        }

        // 进行登录操作
        form.on('submit(login)', function (data) {
            data = data.field;
            // 加密
            data.password = hex_sha256(data.password + salt);

            startLoading();
            miniAjax.postJSON({
                url: '/auth/login',
                data: JSON.stringify(data),
                success: function (res) {
                    stopLoading();
                    if (res.code == 0) {
                        sessionStorage.setItem('token', res.data);
                        sessionStorage.setItem('username', data.username);
                        layer.msg('登录成功，欢迎回来!', {
                            time: 1000
                        }, function () {
                            window.location = '/';
                        });
                    } else {
                        layer.msg(res.msg, {time: 1000});
                    }
                },
                error: function (res) {
                    stopLoading();
                    layer.msg(res, {time: 1000, icon: 2});
                }
            });
            return false;
        });
    });

    function startLoading() {
        var loginBtn = document.querySelector('#login');
        loginBtn.classList.add('layui-disabled');
        loginBtn.setAttribute('disabled', true);
        loginBtn.innerHTML = '<span>登录中</span><i class="layui-icon layui-icon-loading layui-anim layui-anim-rotate layui-anim-loop"></i>';
    }

    function stopLoading() {
        var loginBtn = document.querySelector('#login');
        loginBtn.classList.remove('layui-disabled');
        loginBtn.removeAttribute('disabled');
        loginBtn.innerHTML = '<span>登 录</span>';
    }
</script>
</body>
</html>